package user

import (
	cachePkg "HeadLineNews/pkg/db/cache"
	"github.com/gin-gonic/gin"
	"github.com/go-redis/redis/v8"
)

type Cache interface {
	RegUserRegisterToken(c *gin.Context, userId string) (token string, err error)
	RegUserLoginToken(c *gin.Context, userId string) (token string, err error)
}

type cache struct {
	cli *redis.Client
}

func NewCache() Cache {
	return &cache{cli: cachePkg.UserTokenCache()}
}

// RegUserRegisterToken 用户注册成功之后签发 token
func (cache *cache) RegUserRegisterToken(c *gin.Context, userId string) (token string, err error) {
	return cachePkg.RegToken(cache.cli, userId)
}

// RegUserLoginToken 用户登录成功之后签发 token
func (cache *cache) RegUserLoginToken(c *gin.Context, userId string) (token string, err error) {
	return cachePkg.RegToken(cache.cli, userId)
}